<template>
	<view class="main">
		<!-- 用户头像 -->
		<view class="avatar">
			<image style="height: 100%;width: 100%;" v-if="userInfo.headimage" :src="userInfo.headimage"></image>
			<image style="height: 100%;width: 100%;" v-else
				src="https://applet.youtuyiliao.com/profile/avatar/2022/12/29/bb21da5b0e6b56d28aa892072c69b9e.png">
			</image>
		</view>
		<!-- 用户昵称 -->
		<view class="username">
			{{ userInfo.nickName || '暂未设置' }}
		</view>

		<view class="phone">
			<text>手机号</text>
			<text>{{ userInfo.phone || '暂未设置' }}</text>
		</view>


		<view class="login-btn" @click="wxGetUserInfo">
			修改个人信息
		</view>
		<!-- <view class="login-btn" >
		绑定手机号
		</view> -->
	</view>
</template>

<script>
import { setToken } from "@/utils/auth.js"
import { imageUrl } from '@/config.js'
import { getwxOpenId, wxOpenIdLogin, getUserMessage } from "@/api/feixiang/application.js"
export default {
	data() {
		return {
			phone: '',
			role: '',
			userInfo: {},
		}
	},
	mounted() {
		this._getUserMessage()
	},
	created() {
		this.getToken()
	},
	filters: {
		filterUrl(val) {
			if (!val) {
				return imageUrl + '/profile/avatar/2022/11/19/e7MMHQucVQFg657700a96022645bd964aa0b33d76e23_20221119094612A008.png'
			} else {
				return val
			}
		}
	},
	methods: {
		// 获取code
		getToken() {
			wx.login({
				success: async res => {
					console.log(res, '获取code');
					const code = res.code
					const res2 = await getwxOpenId({
						code,
					})
					console.log(res2, '获取wxOpenId');
					const wxOpenId = res2.data.wxOpenId
					const res3 = await wxOpenIdLogin({
						openid: wxOpenId,
					})
					setToken(res3.data.token)
					this._getUserMessage()
					// console.log(res3,222);
				}
			})
		},
		async _getUserMessage() {
			const res = await getUserMessage()
			console.log(res);
			this.userInfo = res.data
		},
		wxGetUserInfo() {
			uni.navigateTo({
				url: "/sickbed/pages/feixiangCaringVersion/login/getMess"
			})
		},

	}
}
</script>

<style scoped>
.phone {
	width: 686rpx;
	height: 80rpx;
	margin-left: 32rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-bottom: 4rpx solid #F7F7F7;
	font-size: 40rpx;
}

.login-btn {
	position: fixed;
	bottom: 120rpx;
	left: 50%;
	transform: translateX(-50%);
	width: 300rpx;
	height: 80rpx;
	border-radius: 80rpx;
	background-color: #00bcb2;
	color: #fff;
	font-size: 40rpx;
	line-height: 80rpx;
	text-align: center;

}

.main {
	padding-top: 58rpx;
}

.avatar {
	display: block;
	width: 160rpx;
	height: 160rpx;
	/* background-color: #8df; */
	margin-left: 50%;
	transform: translateX(-50%);
	border-radius: 50%;
	overflow: hidden;
	padding: 0;
}

.username {
	width: 100%;
	text-align: center;
	font-size: 50rpx;
	margin-top: 28rpx;
}

.ipt {
	padding: 0 32rpx;
}

.phone-ipt {
	border-bottom: 2rpx solid #F7F7F7;
	position: relative;
}

.phone-ipt-text {
	position: absolute;
	bottom: 10rpx;
	left: 0;
	font-size: 32rpx;
}

.role-ipt {
	border-bottom: 2rpx solid #F7F7F7;
	position: relative;
}

.role-ipt-text {
	position: absolute;
	bottom: 10rpx;
	left: 0;
	font-size: 32rpx;
}
</style>
